angular.module('starter.controllers', [])

  .controller('DashCtrl', function ($scope) {
  })

  .controller('ChatsCtrl', function ($scope, Chats) {
    // With the new view caching in Ionic, Controllers are only called
    // when they are recreated or on app start, instead of every page change.
    // To listen for when this page is active (for example, to refresh data),
    // listen for the $ionicView.enter event:
    //
    //$scope.$on('$ionicView.enter', function(e) {
    //});

    $scope.chats = Chats.all();
    $scope.remove = function (chat) {
      Chats.remove(chat);
    };
  })

  .controller('ChatDetailCtrl', function ($scope, $stateParams, Chats) {
    $scope.chat = Chats.get($stateParams.chatId);
  })

  .controller('AccountCtrl', function ($scope) {
    $scope.settings = {
      enableFriends: true
    };
    var src = "myrecording.mp3";//建立媒体对象参数1：媒体对象路径，mp3文件存放在sd卡根目录下。
    // success callback
    var succ = function () {//建立媒体对象参数2：成功回调函数
      alert('recordAudio():Audio Success');
      console.log("recordAudio():Audio Success");
    }
    var erro = function (err) {//建立媒体对象参数3：失败回调函数
      alert("recordAudio():Audio Error: " + err.code);
      console.log("recordAudio():Audio Error: " + err.code);
    };
    var mediaRec = new Media(src, succ, erro);//建立媒体对象

    // Record audio
    $scope.goRecording = function () {
      mediaRec.startRecord();//开始录音
    }
    // Record audio
    $scope.stopRecording = function () {
      mediaRec.stopRecord();//结束录音
    }
    // Record audio
    $scope.playRecord = function () {
      mediaRec.play();//播放
    }
  });
